#ifndef _TEXTURE_H_
#define _TEXTURE_H_

#include "Stream.h"

enum
{
	BBM_PALETTE = 0x01,		//Has palette data
	BBM_COLOR_KEY = 0x02,	//has color key (the transparent color)
	BBM_ALPHA = 0x04,		//has alpha data
	BBM_HAS_MODULE = 0x08,	//has module data
	
	BBM_COMPRESSION_RLE = 0x10	//the pixel data is compressed by RLE. If has module, it's compressed per module.
};

//@brief this is image type of bbm file.
enum imgFormat
{
	PAL256 = 1<<0,
	RGBA4444 = 1<<1,
	RGBA5551 = 1<<2,
	RGB565 = 1<<3,
	RGBA8888 = 1<<4,
	ALPHA = 1<<5
};

typedef struct _TexInfo{
	const char*	filename;
	GLuint	name;
	u16		width;
	u16		height;
	int		ShaderInfoId;
	int		ref;
	T_U32	size; //VMR size
#ifdef _USE_PALIMAGE_BUFFER
	char*	pData; //image data buffer
#endif
} TexInfo;

extern const char* LoadTexture(int texIdx);
extern int LoadTexture(const char* filename);

#define isNone			(0)
#define isUniformColor	(1<<0)
#define isLiner			(1<<1)
#define isTexture		(1<<2)

//#pragma pack(push, 1)

struct CustomShaderInfo
{
	int						imgFmt;
    tIPLBuiltinStateVector	ShaderVector;
	int						Flag;
    //GLboolean				bUniform;
    //GLboolean				bColor;
    //GLboolean				bTexture;
	GLenum					InternalFormat;
	GLenum					Type;    
};
//#pragma pack(pop)

//enum StateVectorInfo {
//	SV_UniformBlendINGFP = 0,
//	SV_COLORFP,
//	SV_COLORBLENDINGFP,
//	SV_4444NEARESTBLENDINGFP,
//	SV_4444LINEARBLENDINGFP,
//	SV_4444LINEARMODWITHUNIFORMFP,
//};
void setStateVector(int id_);

class TextureManager
{
public:
	static void LoadFile(void* object, CFileStream *pFS);
	// void LoadImageList(char* buf, int size);
	int GetTexIndex(const char * filename);
	friend const char* LoadTexture(int texIdx);
	friend int LoadTexture(const char* filename);
	 TextureManager(void);
	~TextureManager();

	bool Init();

	//bool Add(int texIdx);
	//bool Add(const char * fn);
	//bool Add(int pal[], int size);
	void GenTex(CMemoryStream *pFS, int texIdx);
	void Release(int texIdx);
	void Release(int pal[], int size);
	void Release(const char *pResName);
	//void ReleaseFilename(const char * fn);
	//void ReleaseFilename(int texName);

	void Delete(int texIdx);
	void Reset();
	const TexInfo * GetTex(int texIdx);
	//const TexInfo * GetTex( const char * fn);

	int GetTexNum(){ return m_texMaxNum; }
	//int GetIdx(Texture tex);

private:
	GLuint GetIdleTexName(T_U32 size);
	int m_texMaxNum;
	TexInfo *m_texInfo;
};

#endif // _TEXTURE_H_
